<?php
include 'DBconn.php';
class StateMaster
{
    public function getAllStates()
    {
        $result=mysql_query("select * from state_header where activestatus=1") or die(mysql_error());
        $res_arr=array();
        while($row=mysql_fetch_object($result))
        {
            $tmp=new VoStateMaster();
            $tmp->country_fk=(int)$row->country_fk;
            $tmp->serialnumber=(int)$row->serialnumber;
            $tmp->state_name=$row->state_name;
            $tmp->cre_userid_fk=(int)$row->cre_userid_fk;
            $tmp->cre_datetime=$row->cre_datetime;
            $tmp->activestatus=(boolean)$row->activestatus;
            $res_arr[]=$tmp;
        }
         mysql_free_result($result);
    return $res_arr;
    }
    public function addNewState($VObject)
    {
      $cls=array();
      $query="insert into state_header(country_fk,state_name,cre_userid_fk,cre_datetime,activestatus) values('$VObject->country_fk','$VObject->state_name','$VObject->cre_userid_fk','$VObject->cre_datetime',1)";
      $s=mysql_query($query) or die(mysql_error());
      if ($s=1){mysql_query("COMMIT");}
      else{mysql_query("ROLLBACK");}
      return $this->getAllStates();
      //$result=mysql_query("Select * from state_header ORDER BY serialnumber DESC LIMIT 1 ") or die(mysql_error());
//      $row=mysql_fetch_object($result);
//      $cls[]=$row;
//      return $cls;
    }
    public function editState($VObject)
    {
      $query="update state_header set country_fk='$VObject->country_fk',state_name='$VObject->state_name',cre_userid_fk='$VObject->cre_userid_fk',cre_datetime='$VObject->cre_datetime' where serialnumber='$VObject->serialnumber'";
      $s=mysql_query($query) or die(mysql_error());
      if ($s=1){mysql_query("COMMIT");}
      else{mysql_query("ROLLBACK");}
      return $this->getAllStates();
      
    }
    public function deleteState($serialnumber)
    {
        $s=mysql_query("update state_header set activestatus=0 where serialnumber='$serialnumber'") or die(mysql_error());
        if ($s=1){mysql_query("COMMIT");}
        else{mysql_query("ROLLBACK");}
        
    }
}
//$vo=new voStateMaster();
//$vo->country_fk=1;
//$vo->cre_userid_fk=1;
//$vo->serialnumber=1;
//$vo->state_name="Kerala";
//$s=new StateMaster;
//echo $s->deleteState(1);
class VoStateMaster{
    var $country_fk;
    var $serialnumber;
    var $state_name;
    var $cre_userid_fk;
    var $cre_datetime;
    var $activestatus;
}


?>